package com.veryGood.controller.sale;

import com.veryGood.common.result.LayuiResultJson;
import com.veryGood.common.result.R;
import com.veryGood.domain.pojo.SalesInfo;
import com.veryGood.service.SaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/sale")
@Api(value = "销售管理接口",tags = "销售管理接口")
public class SaleController {
    @Autowired
    private SaleService saleService;

    // 添加销售订单
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public R save(@RequestBody SalesInfo salesInfo) {//接收是json格式的对象
        return saleService.addSale(salesInfo);
    }

    // 查询所有药品信息-带分页
    @RequestMapping(value = "/findSaleAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有销售订单信息-分页", notes = "验证分页参数：当前页码数与每页显示的条数", httpMethod = "get", response = LayuiResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码数", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页显示的条数", required = true, dataType = "String", paramType = "query")
    })

    @ResponseBody
    public LayuiResultJson findSaleAll(@RequestParam(required = true) Integer page, @RequestParam(required = true) Integer limit) {
        return saleService.findSaleAll(page,limit);
    }

    // 删除
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public R delete(Integer id) {
        return saleService.delSaleById(id);
    }
}
